import { v3, Vec3, Quat, find, tween } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { Extension } from '../../../sgame/extension/Extension';
const { ccclass, property } = _decorator;

@ccclass('NodeExt')
export class NodeExt extends Component {
    start() {
        Extension.Init();
        this.testMove();
        this.testWorldMove();
        this.testScale();
        this.testWorldScale();
        this.testRotate();
        // (this.node.getComponent(Button) as Button);
    }

    testMove() {
        let node = this.node.Child("moveExt/local");
        let originPos = node.position.clone();
        let deltaPos = originPos.clone();
        tween(node).sequence(
            node.DOMove(2, v3(1, 1, 1)).repeat(2),
            node.DOMoveX(2, 1),
            node.DOMoveY(2, 1),
            node.DOMoveZ(2, 1),
            node.DOMoveTo(2, originPos),
            node.DOMoveTo(2, Vec3.add(deltaPos, originPos, v3(1, 1, 1))),
            node.DOMoveToX(2, originPos.x),
            node.DOMoveToY(2, originPos.y),
            node.DOMoveToZ(2, originPos.z)
        ).start();
    }

    testWorldMove() {
        let node = this.node.getChildByPath("moveExt/world");
        let originPos = node.worldPosition.clone();
        let deltaPos = originPos.clone();
        tween(node).sequence(
            node.DOMoveWorld(2, v3(1, 1, 1)),
            node.DOMoveWorldX(2, 1),
            node.DOMoveWorldY(2, 1),
            node.DOMoveWorldZ(2, 1),
            node.DOMoveWorldTo(2, originPos),
            node.DOMoveWorldTo(2, Vec3.add(deltaPos, originPos, v3(1, 1, 1))),
            node.DOMoveWorldToX(2, originPos.x),
            node.DOMoveWorldToY(2, originPos.y),
            node.DOMoveWorldToZ(2, originPos.z)
        ).start();
    }

    testScale() {
        let node = this.node.getChildByPath("scaleExt/local");
        let originScale = node.scale.clone();
        let deltaScale = originScale.clone();
        tween(node).sequence(
            node.DOScale(2, v3(1.5, 1.5, 1.5)),
            node.DOScaleX(2, 1.5),
            node.DOScaleY(2, 1.5),
            node.DOScaleZ(2, 1.5),
            node.DOScaleTo(2, originScale),
            node.DOScaleTo(2, Vec3.add(deltaScale, originScale, v3(1, 1, 1))),
            node.DOScaleToX(2, originScale.x),
            node.DOScaleToY(2, originScale.y),
            node.DOScaleToZ(2, originScale.z)
        ).start();
    }

    testWorldScale() {
        let node = this.node.getChildByPath("scaleExt/world");
        let originScale = node.worldScale.clone();
        let deltaScale = originScale.clone();
        tween(node).sequence(
            node.DOScaleWorld(2, v3(1.5, 1.5, 1.5)),
            node.DOScaleWorldX(2, 1.5),
            node.DOScaleWorldY(2, 1.5),
            node.DOScaleWorldZ(2, 1.5),
            node.DOScaleWorldTo(2, originScale),
            node.DOScaleWorldTo(2, Vec3.add(deltaScale, originScale, v3(1, 1, 1))),
            node.DOScaleWorldToX(2, originScale.x),
            node.DOScaleWorldToY(2, originScale.y),
            node.DOScaleWorldToZ(2, originScale.z)
        ).start();
    }

    testRotate() {
        let node = this.node.getChildByPath("rotateExt/local");
        let originEuler = node.eulerAngles.clone();
        let deltaEuler = originEuler.clone();
        tween(node).sequence(
            node.DORotate(2, v3(90, 90, 90)),
            node.DORotateX(2, 90),
            node.DORotateY(2, 90),
            node.DORotateZ(2, 90),
            node.DORotateTo(2, originEuler),
            node.DORotateTo(2, Vec3.add(deltaEuler, originEuler, v3(90, 90, 90))),
            node.DORotateToX(2, originEuler.x),
            node.DORotateToY(2, originEuler.y),
            node.DORotateToZ(2, originEuler.z)
        ).start();
    }

    // testWorldRotate() {
    //     let node = this.node.getChildByPath("rotateExt/world");
    //     let originEuler = node.eulerAngles.clone();
    //     let deltaEuler = originEuler.clone();

    //     node.setWorldRotationFromEuler
    //     tween(node).sequence(
    //         node.DORotateWorld(2, v3(90, 90, 90)),
    //         node.DORotateWorldX(2, 90),
    //         node.DORotateWorldY(2, 90),
    //         node.DORotateWorldZ(2, 90),
    //         node.DORotateWorldTo(2, originEuler),
    //         node.DORotateWorldTo(2, Vec3.add(deltaEuler, originEuler, v3(90, 90, 90))),
    //         node.DORotateWorldToX(2, originEuler.x),
    //         node.DORotateWorldToY(2, originEuler.y),
    //         node.DORotateWorldToZ(2, originEuler.z)
    //     ).start();
    // }
}
